package cn.itzzx.resume.controller;

import cn.itzzx.resume.pojo.Resume;
import cn.itzzx.resume.service.ResumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 *
 * @author Martin
 * @since 1.0
 */
@RequestMapping("resume")
@Controller
public class ResumeController {

    @Autowired
    private ResumeService resumeService;

    @RequestMapping("list")
    public ModelAndView list() {
        ModelAndView modelAndView = new ModelAndView();
        List<Resume> list = resumeService.listAll();
        modelAndView.addObject("resumes", list);
        modelAndView.setViewName("resume");
        return modelAndView;
    }

    @RequestMapping("deleteById/{id}")
    public String deleteById(@PathVariable Long id){
        resumeService.deleteById(id);
        return "redirect:/resume/list";
    }

    /**
     * 编辑和删除
     * @param resume
     * @return
     */
    @RequestMapping("saveAndUpdate")
    public String update(Resume resume){
        if(StringUtils.isEmpty(resume.getId())){
            resumeService.save(resume);
        }else{
            resumeService.update(resume);
        }
        return "redirect:/resume/list";
    }


}
